#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    zt = new Teacher(this);

    st = new Student(this);

    lable = new QLabel(this);

    lable->show();

    //连接老师和学生

    // connect(zt, &teacher::teach, st, &student::study);

    //有参数信号和槽函数连接

    //函数指针 指向函数地址

    void(Teacher:: *teacherSignal)(QString) = &Teacher:: teach;

    void(Student:: *stbook)(QString) = &Student:: treat;

    connect(zt, teacherSignal, st, stbook);
    connect(zt,teacherSignal,this,&MainWindow::showBooks);

    //下课

    classover();

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::classover()
{
    // 触发老师上课的信号

    // 老师上课的信号属于自定义信号， 触发自定义信号关键字 emit

    emit zt -> teach(); // 触发无参信号

    emit zt -> teach("chemical");


}

void MainWindow::showBooks(QString book)
{

    if(book != ""){
        lable->setText(book);
    }
}

